import com.pzhu.mapper.UserMapper;
import com.pzhu.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MainTest {
    public static void main(String[] args) throws IOException {
        //加载核心配置文件，获取 SqlSessionFactory 对象
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //获取 SqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //用sqlSession执行sql语句
        //List<User> users = sqlSession.selectList("UserMapper.AllSelect");
        UserMapper mapper=sqlSession.getMapper(UserMapper.class);
        List<User> users = mapper.AllSelect();
        //释放资源
        sqlSession.close();

        System.out.println(users);
    }
}